/**
 * Created by pankaj on 25/10/14.
 * It accepts files and then make html to render it.
 */
define(['jquery', 'mustache', 'module/template/homeTemplate'], function ($, Mustache, template) {

    var imageRender = function (files) {
        var imageArea = $(template['home-update-form-image']);
        var imageItem = function (file) {
            var imageItem = $(Mustache.render(template['home-update-form-image-item'], {name: file.name}));
            return imageItem;
        };

        $.each(files, function (index, file) {
            var imageHtml = imageItem(file);
            imageArea.append(imageHtml);
            // remove This file item.

            imageHtml.find('a:last').click(function () {
                // remove the model.
                files.splice(index, 1);
                // remove the view.
                imageHtml.remove();
            });
        });
        return imageArea;
    };

    return imageRender;


});